package com.car.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.car.entity.User;
import com.car.entity.UserExample;
import com.car.service.UserMapperService;


@Controller
public class LoginController {
	
	@Autowired
	@Qualifier("userService")
	private UserMapperService userService;

	/**
	 * 跳转到登陆界面
	 * @return
	 */
	@RequestMapping("/Login.html")
	public String Login(){
		return "login";
	}
	
	@RequestMapping("Index")
	public String Index(String username, String password,HttpSession session){
		UserExample example = new UserExample();
		UserExample.Criteria criteria = example.createCriteria();
		criteria.andUsernameEqualTo(username);
		criteria.andPasswordEqualTo(password);
		User user = userService.Login(example);
		if(user!=null){
			session.setAttribute("loginUser", user);
			return "index";
		}
		return "forward:/Login.html";
	}
}
